package com.heima.pri02;

import java.io.*;
import java.util.Arrays;

public class ZiFuHuanChongLiu03 {
    public static void main(String[] args) throws IOException {
        //练习：读取文件中的数据，排序后再次写到本地文件
        //步骤:1.读取数据s
        BufferedReader bu = new BufferedReader(new FileReader("day11\\sout.txt"));
        String line = bu.readLine();
        System.out.println("数据为" + line);
        bu.close();
        //按照空格进行切割
        String[] split = line.split(" ");
        int arr[] = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            String small = split[i];
            int i1 = Integer.parseInt(small);
            arr[i] = i1;
        }
        //2.进行排序
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        //3.写回本地
        BufferedWriter B = new BufferedWriter(new FileWriter("day11\\sout.txt"));
        for (int i = 0; i < arr.length; i++) {
            B.write(arr[i] + " ");
            B.flush();
        }
        B.close();
    }


}

